//自动打印订单

define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";
	
	var wind_async=require('ddf_wind_async');

	var base=require('component-base');
	
var tips_index=0;

var checkTime = '';

var timer = null;

/**
 * 
 */
exports.init=function(m) {
	var now = new Date();
	checkTime = '';//清空
	checkTime += now.getFullYear();
	checkTime += (now.getMonth()+1)<10?'0'+(now.getMonth()+1):(now.getMonth()+1);
	checkTime += now.getDate()<10?'0'+now.getDate():now.getDate();
	checkTime += now.getHours()<10?'0'+now.getHours():now.getHours();
	checkTime += now.getMinutes()<10?'0'+now.getMinutes():now.getMinutes();
	checkTime += now.getSeconds()<10?'0'+now.getSeconds():now.getSeconds();
	//alert(checkTime);
//	checkTime = '20141223104257';
	timer = window.setInterval(exports.checkOrder, 30000); 
};

exports.checkOrder = function(){
	var params={
			"checkTime":checkTime
	        };
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.checkOrderAdd,params));
		
		loadCheckOrderCallBack(data);
		
	}))().start();
};

function loadCheckOrderCallBack(data){
	if(data["code"]==1){
		if(data["orderList"].length > 0){
			sysTips(data["orderList"][0]["ORDERID"]);
			if(document.getElementById("_upload_frame_autoprint")==null){
				$(document.body).append('<iframe class="opacitystyle" id="_upload_frame_autoprint" name="_upload_frame_autoprint"></iframe>');
			}
			get2post(CTX+"/admin/printOrder.jsp?orderId="+data["orderList"][0]["ORDERID"],"_upload_frame_autoprint");
			checkTime = data["orderList"][0]["CREATETIME"];
		}
	}else{
		
	}
}

exports.clear = function(){
    if(timer!=null){
    	clearInterval(timer);
    	timer = null;
    }
};

exports.setPrintType = function(t){
	var params={
			"printType":t
	        };
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.order.setPrintType,params));
		
		if(data["code"]!=1){
			alert(data.message);
		}
		
	}))().start();
};


});
